//
//  DHHomeCommentsCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/4/25.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHHomeCommentsCell.h"
#import "DHHomeComments_Cell.h"
#import "DHNewsDetailController.h"

@interface DHHomeCommentsCell()<UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) NSArray *itemArr; //数据

@end

@implementation DHHomeCommentsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.moreButton.layer.cornerRadius = self.moreButton.height / 2;
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.tableView registerNib:[UINib nibWithNibName:@"DHHomeComments_Cell" bundle:nil] forCellReuseIdentifier:kDHHomeComments_Cell];
}

- (NSArray *)itemArr{
    if (!_itemArr) {
        _itemArr = [NSArray array];
    }
    return _itemArr;
}

- (void)updateCellWithArray:(NSArray *)arr{
    self.itemArr = arr;
    [self.tableView reloadData];
}

#pragma mark - UITableViewDelegate and UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.itemArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 95;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DHHomeComments_Cell *cell = [tableView dequeueReusableCellWithIdentifier:kDHHomeComments_Cell forIndexPath:indexPath];
    NSDictionary *dic = self.itemArr[indexPath.row];
    [cell.imgView dh_setImageURLString:[dic objectForKey:@"cover"]];
    [cell.headImageView dh_setImageURLString:[[dic objectForKey:@"owner"] objectForKey:@"photo"]];
    cell.titleLabel.text = [[dic objectForKey:@"owner"] objectForKey:@"nickname"];
    cell.nameLabel.text = [[dic objectForKey:@"owner"] objectForKey:@"title"];
    cell.summaryLabel.text = [dic objectForKey:@"summary"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = self.itemArr[indexPath.row];
    DHNewsDetailController *vc = [[DHNewsDetailController alloc] initWithArticleID:[dic objectForKey:@"_id"]];
    vc.hidesBottomBarWhenPushed = YES;
    [self.viewController.navigationController pushViewController:vc animated:YES];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
